package com.coincalf.web;

import com.baomidou.mybatisplus.plugins.Page;
import com.coincalf.entity.DigitalEncyclopedia;
import com.coincalf.framework.enums.CategoryEnum;
import com.coincalf.framework.http.Response;
import com.coincalf.service.DigitalEncyclopediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dc")
@Api(value = "学院资讯", description = "学院资讯")
public class DigitalEncyclopediaController {

    @Autowired
    private DigitalEncyclopediaService digitalEncyclopediaService;


    /**
     * 根据分类查询学院资讯信息
     *
     * @param category
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/info")
    @ApiOperation(value = "根据分类查询学院资讯信息", notes = "根据分类查询学院资讯信息", httpMethod = "GET")
    public Response dcInfo(String category, Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 10 : pageSize;
        Page<DigitalEncyclopedia> dcs = digitalEncyclopediaService.queryByCategory(category, pageNo, pageSize);
        return Response.ok(dcs);
    }

    /**
     * 获取所有分类
     *
     * @return
     */
    @GetMapping("/categories")
    @ApiOperation(value = "获取所有分类", notes = "获取所有分类", httpMethod = "GET")
    public Response categories() {
        CategoryEnum[] values = CategoryEnum.values();
        List<String> list = new ArrayList<>(values.length);
        for (CategoryEnum c : values) {
            list.add(c.getName());
        }
        return Response.ok(list);
    }

}
